package com.ruoyi.system.Controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.CmAbnormalInfo;
import com.ruoyi.system.domain.CmManagerInfo;
import com.ruoyi.system.domain.CmUserHtclockin;
import com.ruoyi.system.domain.CmUserInfo;
import com.ruoyi.system.domain.Vo.CmUserHtDto;
import com.ruoyi.system.domain.Vo.CmUserHtHty;
import com.ruoyi.system.domain.Vo.R;
import com.ruoyi.system.service.ICmAbnormalInfoService;
import com.ruoyi.system.service.ICmUserHtclockinService;
import com.ruoyi.system.service.ICmUserInfoService;
import com.ruoyi.system.service.WxMethodService;
import org.apache.poi.ss.formula.functions.Now;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

@RestController
public class WxUserController extends BaseController {
    @Autowired
    private ICmUserInfoService cmUserInfoService;
    @Autowired
    private ICmUserHtclockinService cmUserHtclockinService;
    @Autowired
    private WxMethodService wxMethodService;
    @Autowired
    private ICmAbnormalInfoService cmAbnormalInfoService;

    //根据openid查询个人信息
    @PostMapping(value="/WxInfo/{openid}")
    public R UserinfoService(CmUserInfo cmUserInfo,@PathVariable("openid")String openid){
       return cmUserInfoService.selectCmUserInfoOpenId(cmUserInfo,openid);
    }

    //根据openid+日期 查询当日打卡记录
    @PostMapping(value="/Wx/NowhtHty")
    public R selectNowhtHty(CmUserHtHty cmUserHtHty,String NowDate){
        return cmUserHtclockinService.selectWxCmUserHtNowdate(cmUserHtHty,NowDate);
    }


    @PostMapping(value = "/Wx/htHty")
    public R selecthtHty(String openid){
        return cmUserHtclockinService.selectWxCmUserHthtyOpenId(openid);
    }

    //打卡提交
    @PostMapping(value="/Wx/htSubmit")
    public R insertHtHty(CmUserHtDto cmUserHtDto) {
        System.out.println(cmUserHtDto);
        return wxMethodService.insertHty(cmUserHtDto);
    }

    @GetMapping(value ="/Wx/ManagerPhone")
    public R selectManagerPhone(){
        return wxMethodService.selectManagerPhone();
    }

    //根据openid请求基本信息
    @PostMapping(value = "/Wx/Userinfo")
    public R selectUserInfo(String openid){
        return  wxMethodService.selectWxUserInfo(openid);
    }

    //社管根据openid请求基本信息
    @PostMapping(value="/Wx/Managerinfo")
    public R selectManagerInfo(String openid){
        return wxMethodService.selectManagerInfo(openid);
    }

    //个人信息修改
    @PostMapping(value ="/Wx/UpdateUserinfo")
    public R updateUserInfo( CmUserInfo cmUserInfo){
        return wxMethodService.updateWxUserInfo(cmUserInfo);
    }

    //社管信息修改
    @PostMapping(value = "/Wx/UpdateManagerInfo")
    public R updateManagerInfo(CmManagerInfo  cmManagerInfo){
        return wxMethodService.updateManagerInfo(cmManagerInfo);
    }

    //根据openid查询当前家庭成员
    @PostMapping(value="/Wx/selectOwIdBlock")
    public R selectBlockUser(String openid){
        return wxMethodService.selectBlockUser(openid);
    }

    //添加成员
    @PostMapping(value="/Wx/insertcourtBlock")
    public R updateUserInfoBlock(String openid,String phone){
        return wxMethodService.updateUserInfoBlock(openid,phone);
    }

    //居民异常求助
    @PostMapping(value="/Wx/abnormalSubmit")
    public R abnormalSubmit(String openid,String remark){
        return wxMethodService.abnormalSubmit(openid,remark);
    }

    //社管查询异常求助列表
    @GetMapping(value = "/Wx/abnormalList")
    public TableDataInfo abnormalList(CmAbnormalInfo cmAbnormalInfo){
        startPage();
        List<CmAbnormalInfo> cmAbnormalInfos = cmAbnormalInfoService.selectCmAbnormalInfoList(cmAbnormalInfo);
        return getDataTable(cmAbnormalInfos);
    }

    //社管异常求助处理修改
    @PostMapping(value = "/wx/abnormalApprove")
    public R abnormalApprove(Long id,String openid,String ManagerRemark,Integer Status){
        return  wxMethodService.abnormalApprove(id,openid,ManagerRemark,Status);
    }

}
